#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>


struct date
{
       int ngay;
       int thang;
       int nam;       
};
typedef struct nhanvien
{
        char ho_ten[30];
        struct date ngay_sinh;
        char don_vi[50];
        int nam_vao_lam;
        float he_so_luong;
};

nhanvien *p;
// ham nhap dau vao 
nhanvien *NhapDS(int n)
{
        int i,temp;
        float tam;
        p=(nhanvien*)malloc(n*sizeof(nhanvien));
        if(p==NULL)
        {
              printf("\n Loi cap phat bo nho !");
              getch();
              exit(0);      
        }        
        else
        {
               printf("\n Nhap vao thong tin ve nhan vien \n");
               for(i = 0; i < n; i++)
               {
                     printf("\n Nhan vien thu %d ",i+1);
                     //nhap vao ho ten
                     printf("\n Ho va Ten : ");
                     fflush(stdin);
                     gets((p+i)->ho_ten);
                     //nhap vao nam cong tac
                     printf("\nDon vi cong tac :");
                     gets((p+i)->don_vi);
                     //nhap vao ngay thang nam sinh
                     printf("\n Nhap vao ngay thang nam sinh");
                     printf(" \nNgay sinh : "); 
                     scanf("%d",&temp);
                     (p+i)->ngay_sinh.ngay=temp;
                     printf("\tThang sinh :");
                     scanf("%d",&temp);
                     (p+i)->ngay_sinh.thang=temp;
                     printf("\tNam sinh :");
                     scanf("%d",&temp);
                     (p+i)->ngay_sinh.nam=temp;
                     //nhap vao nam bat dau lam
                     printf("\n Nam vao lam :");    
                     scanf("%d",&temp);
                     (p+i)->nam_vao_lam=temp;
                     //nhap vao he so luong
                     printf("\n He so luong : ");
                     scanf("%f",&tam);
                     (p+i)->he_so_luong=tam;
                    
               }  
               puts("\n");
        }
        return(0);
}
//Ham chuan hoa xau
/*
void ChanHoa(char *s)
{
     int i;
     //1 Xoa khoang trang dau xau va cuoi xau
         // 1.1 Xoa khoang trang dau xau
         while(*s)
         {
            if(*s=='')
            {
                  s++;          
            }
         }    
          //1.2 Xoa khoang trang cuoi xau
         while(*(s+strlen(s)-1)='')
         {
            s+strlen(s)-1 = s+strlen(s);
         }
     //Giua cac tu cach nhau mot khoang trang
     while(s < strlen(s) )
     {
             if(*(s+i)==''&&*(s+i+1)=='')
             {
                  for(int j = i; j < strlen(s)-1; j++)
                  {
                        s+j=s+j+1;        
                  }                          
             }               
             i++;
     }
     //3 Viet hoa chu cai dau tien cua mot tu 
         //3.1 Chuyen tat ca cac chu thanh chu thuong
         for(i = 0; i< strlen(s); i++)
         {
           *(s+i)=tolower(*(s+i));      
         }
         //3.2 chuyen chu cai dau thanh hoa
         for(i = 0; i < strlen(s); i++)
         {
               if(*(s+i)=''&&*(s+i+1)!='')
               {
                  *(s+i+1)=toupper(*(s+i+1));                        
               }      
         }
         
     
     
}
*/
void InDS(nhanvien *p, int n)
{
          for(int i = 0; i < n; i++)
          {
                puts("\n");
                printf("\n Nhan vien thu %d",i+1);
               printf("\n\t Ho va ten : %s",(p+i)->ho_ten);
               printf("\n\t sinh  ngay :%d/%d/%d",(p+i)->ngay_sinh.ngay,(p+i)->ngay_sinh.thang,(p+i)->ngay_sinh.nam);
               printf("\n\t Ten don vi cong tac : %s",(p+i)->don_vi);
               printf("\n\t So nam cong tac :%d",(p+i)->nam_vao_lam);
               printf("\n\t He so luong :%6.3f",(p+i)->he_so_luong);
               
          }
          puts("\n");
     
}
/*
voi timkiem()
{
    char tennv[30];
    int kq;
    printf("\n Tim kiem nhan vien theo ho va ten :");
    printf("\n\t Hay cho mot cai ten :");
    scanf("%s",tensv);   
    
}*/
int main()
{
    int n;
    printf("\n Nhap vao n =");
    scanf("%d",&n);
    NhapDS(n);
    //
    int key=0;
    
    while(key!=6)    
    {
               printf("\n --->Menu chon cac hanh dong<--- ");
               printf("\n 1. In lai danh sach nhan vien duoc sap xep theo Ten(neu trung ten thi theo ho)");
               printf("\n 2. Danh sach nhan vien co tham nien cong tac den nam 2010 la 10 nam ");
               printf("\n 3. Danh sach nhan vien co he so luong tu 3.0 tro len ");
               printf("\n 4. Tim kiem nhan vien theo ngay thang nam sinh ");
               printf("\n 5. Xoa nhan vien theo ho ten");
               printf("\n 6. Thoat !");      
               printf("\n\t Nhap vao cong viec duoc chon : ");
               scanf("%d",&key);
               switch(key)
               {
                         case 1: InDS(p,n);
                                 break; 
                         case 2: printf("\n\t\t ma chuong trinh cho cong viec 2");
                                 break;
                         case 3: printf("\n\t\t ma chuong trinh cho cong viec 3");
                                 break;
                         case 4: printf("\n\t\t ma chuong trinh cho cong viec 4");
                                 break;
                         case 5: printf("\n\t\t ma chuong trinh cho cong viec 5");
                                 break;
                         case 6: exit(0);
                                 break;
                         default: {
                                   printf("\n\t\t Ban hay xem huong dan truoc khi su dung chuong trinh ! ");
                                   break;
                                  }
               }            
    }
    getch();
    return (0);    
}
